home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / sviluppo / svilupp2 / amphn192.lha / src / inthandler.a < prev    next >
Text File  |  1996-11-16  |  9KB  |  296 lines

  1. ; inthandler.asm.  Fills our output buffer with delicious audio bytes
  2.  
  3.     INCLUDE "exec/types.i"
  4.     INCLUDE "hardware/custom.i"
  5.     INCLUDE "hardware/intbits.i"
  6.     INCLUDE "hardware/cia.i"
  7.     INCLUDE "utility/hooks.i"
  8.     
  9.     XREF    _ciaa
  10.     XREF    _ciab
  11.         
  12.     XDEF    _AHIhookEntry
  13.     XDEF    _Idle
  14.     XDEF    _InvertIdle
  15.     XDEF    _PerfectIdle
  16.     XDEF    _Record
  17.     XDEF    _PerfectRecord
  18.     
  19.     rsset    0
  20.  
  21. ; IntInfo structure definition
  22. pubIndex     rs.l 1    ; 0  - pointer to next byte to sample to
  23. pubArray    rs.l 1    ; 4  - pointer to beginning of array 
  24. pubSampleAt     rs.l 1    ; 8  - byte-address to sample from
  25. pubHalfIndex    rs.l 1    ; 12 - pointer to halfway point in array 
  26. pubEndIndex    rs.l 1    ; 16 - pointer to end of array 
  27. stTask        rs.l 1    ; 20 - pointer to main task 
  28. ulHalfSignal    rs.l 1    ; 24 - signal for halfway-through-buffer 
  29. ulFullSignal    rs.l 1    ; 28 - signal for end-of-buffer  
  30. ulShiftLeft    rs.l 1    ; 32 - number of bits to shift left for amplify 
  31. ulByteSum    rs.l 1    ; 36 - tally of byte values sampled 
  32. ulSaveByteSum    rs.l 1    ; 40 - save of tally (updated when a signal is set) 
  33. ulThreshhold    rs.l 1  ; 44 - samples above this value trigger higher sampling rate
  34. pubCiahi    rs.l 1  ; 52 - address of high CIA countdown byte
  35. pubCialo    rs.l 1  ; 56 - address of low CIA countdown byte
  36. uwCiavals    rs.l 1  ; 60 - value to put in lo CIA for full rate
  37. uwClearCode    rs.l 1    ; 64 - value to put in intreq() indicate interrupt handled
  38. BIdle        rs.l 1  ; 68 - Boolean (are we idle?)
  39. ulDebug1    rs.l 1  ; 72 - debug output field 1
  40. ulDebug2    rs.l 1  ; 76 - debug output field 2
  41.  
  42. JSRLIB MACRO
  43.     XREF _LVO\1
  44.     JSR  _LVO\1(A6)
  45.     ENDM
  46.  
  47. RECORDBRANCH MACRO
  48. ; checks to see if we're idle, and if we're not, GOTO's the correct 
  49.     MOVE.L    BIdle(A1),D0        ; check BIdle
  50.     CMP.L    #0,D0
  51.     BEQ    _Record            ; If we're not idle, goto Record
  52.     ENDM
  53.  
  54. PERFECTRECORDBRANCH MACRO
  55. ; checks to see if we're idle, and if we're not, GOTO's the correct 
  56.     MOVE.L    BIdle(A1),D0        ; check BIdle
  57.     CMP.L    #0,D0
  58.     BEQ    _PerfectRecord        ; If we're not idle, goto Record
  59.     ENDM
  60.  
  61. ; puts the current sample on the parallel port into D0
  62. GETSAMPLE MACRO
  63.     MOVE.L    pubSampleAt(A1),A5    ; get place to sample from    
  64.     MOVE.B  (A5),D0            ; put the sample in D0
  65.     ADDI.B  #128,D0            ; make it a signed sample
  66.     ENDM
  67.  
  68.  
  69. ; Gets a whole sample from the Perfect Sound digitizer
  70. ; returns it in D0, munges D1
  71. GETPERFECTSAMPLE MACRO
  72.     MOVE.B    #$80,_ciaa+ciaprb    ; latch the value (PB6 low)
  73.     MOVE.B  (_ciaa+ciaprb),D0    ; put the sample in D0
  74.         LSL.L   #2,D0                   ; Shift 6 data bits into high part of byte.
  75.         MOVE.B  (_ciab+ciapra),D1       ; Get miscellaneous bits from CIABPA, contains 2 LSB of sample.
  76.         ANDI.B  #3,D1                     ; Get only the lower 2 bits we want
  77.         OR.B    D1,D0            ; Mix the values together.
  78.     ENDM
  79.     
  80.     
  81. ; expects the sample to be in D0 already
  82. ; returns the amplified sample in D0 
  83. ; also returns the sample in D1 with the other upper 3 bytes of D1 cleared
  84. AMPSAMPLE MACRO
  85.     MOVE.L  ulShiftLeft(A1),D1    ;
  86.     LSL.B    D1,D0            ; shift/amplify
  87.     MOVEQ.L #0,D1            ; make sure upper bytes of D1 are 0
  88.     MOVE.B    D0,D1            ; put sample value into D1
  89.     ENDM
  90.  
  91.  
  92. ; Expects AMPSAMPLE to have been called before, setting up D1
  93. ; with the amplified sample and clear upper 3 bytes
  94. ; Adds the sample to the total and puts the address of the current 
  95. ; output point in the array into A5
  96. ADDVOLUME MACRO
  97.     ADD.L    D1,ulByteSum(A1)    ; add this value to our volume total    
  98.     MOVE.L    pubIndex(A1),A5        ; pubIndex in A5
  99.     MOVE.B    D1,(A5)            ; store the new byte
  100.     ADDQ.L    #1,pubIndex(A1)        ; move pointer to the next entry in the buffer
  101.     ENDM
  102.  
  103.     
  104. ; sets bit PB6 in ciaa.  This tells PerfectSound to resume digitizing
  105. PERFECTDIGITIZE MACRO
  106.     MOVE.B    #$80+$40,_ciaa+ciaprb    ; release the latch (PB6 high)
  107.     ENDM
  108.  
  109.  
  110. ; snapshots the current volume into ulSaveByeNum */
  111. SAVEVOLUME MACRO
  112.     MOVE.L    ulByteSum(A1),ulSaveByteSum(A1)    ; get current volume sum
  113.     MOVE.L    #0,ulByteSum(A1)        ; reset running total
  114.     ENDM
  115.  
  116.  
  117. ; Check the sample in D1 against ulThreshhold.  If it's above
  118. ; the threshhold value, kick up our sampling rate to ulFullRate, and turn BIdle off.
  119. IDLECHECK MACRO
  120.     CMP.L    ulThreshhold(A1),D1    ; compare current sample with threshhold (.L is NECESSARY else sign problems)
  121.     BLT    ExitHandler        ; if not loud enough, we're done!
  122.     
  123.     ; Time to take us out of idle mode! 
  124.     MOVE.L    #0,BIdle(A1)        ; get location of is_Code field
  125.     MOVE.L    #0,ulByteSum(A1)    ; restart counting now
  126.     MOVE.L  pubArray(A1),pubIndex(A1) ; start over at beginning of buffer
  127.     MOVE.L  pubCiahi(A1),A5        ; get address of CIA hi byte
  128.     MOVE.B  uwCiavals+2(A1),(A5)    ; set CIA hi byte
  129.     MOVE.L  pubCialo(A1),A5        ; get address of CIA lo byte
  130.     MOVE.B  uwCiavals+3(A1),(A5)    ; set CIA lo byte
  131.     BRA.S    ExitHandler
  132.     ENDM
  133.  
  134.  
  135.     
  136. ; Enter with:
  137. ;
  138. ; d0 = scratch
  139. ; d1 = INTENAT & INTREQR (scratch)
  140. ; a0 = custom chips (scratch)
  141. ; a1 = is_Data which is our passed in arg, kinda (scratch)
  142. ; a5 = vector to our code (scratch)
  143. ; a6 = pointer to ExecBase (scratch)
  144. ;
  145. ;   section code
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  155. ;;;
  156. ;;; This entry point is for the 8 bit idling routine, without inversion.
  157. ;;;
  158. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  159. _Idle:
  160.     RECORDBRANCH            ; go to record if we're not idle
  161.     GETSAMPLE            ; put sample value into D0
  162.     AMPSAMPLE            ; amplify it as necessary
  163.     IDLECHECK            ; if idle, check sample to see if we should trigger higher sampling rate on it
  164.  
  165.  
  166. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  167. ;;;
  168. ;;; This entry point is for the 8 bit idling routine, with inversion.
  169. ;;;
  170. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  171. _InvertIdle:
  172.     RECORDBRANCH            ; go to record if we're not idle
  173.     GETSAMPLE            ; put sample value into D0
  174.     NOT.B    D0            ; Make it so that 0 = softest, 255 = loudest
  175.     AMPSAMPLE            ; amplify it as necessary
  176.     IDLECHECK            ; if idle, check sample to see if we should trigger higher sampling rate on it
  177.  
  178.  
  179.  
  180.  
  181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  182. ;;;
  183. ;;; This entry point is for the 8 bit idling routine, for the
  184. ;;; PerfectSound, without inversion.
  185. ;;;
  186. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  187. _PerfectIdle:
  188.     PERFECTRECORDBRANCH        ; go to record if we're not idle
  189.     GETPERFECTSAMPLE        ; put sample value into D0
  190.     AMPSAMPLE            ; amplify sample as necessary
  191.     PERFECTDIGITIZE            ; tell PS to continue digitizing
  192.     IDLECHECK            ; if idle, check sample to see if we should trigger higher sampling rate on it
  193.  
  194.  
  195.  
  196.  
  197. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  198. ;;;
  199. ;;; This entry point is for the 8 bit recording routine for the
  200. ;;; PerfectSound digitizer.  The difference is that in the perfect
  201. ;;; sound, only the low 6 bits (PB5-PB0 in CIAA) are used for sample
  202. ;;; data--they are the high six bits of the sample.  PB6 and PB7 are
  203. ;;; used for controlling the sampler, and the low two bits of the
  204. ;;; sample are in POUT and BUSY.  
  205. ;;;
  206. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  207. _PerfectRecord:    
  208.     GETPERFECTSAMPLE        ; put sample value into D0
  209.     AMPSAMPLE            ; amplify sample as necessary
  210.     ADDVOLUME            ; and record it
  211.     PERFECTDIGITIZE            ; tell PS to continue digitizing
  212.     BRA.S        DoSignals    ; Standard recording stuff
  213.  
  214.  
  215.  
  216.  
  217.  
  218. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  219. ;;;
  220. ;;; This entry point is for the 8 bit recording routine.
  221. ;;;
  222. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  223. _Record:    
  224.     GETSAMPLE            ; put sample value into D0
  225.     AMPSAMPLE            ; amplify it as necessary (sample now in D1)
  226.     ADDVOLUME            ; tally its volume & put output address in A5
  227.     BRA.S        DoSignals    ; And do the standard recording stuff
  228.     
  229.     
  230.     
  231.     
  232. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  233. ;;;
  234. ;;;
  235. ;;; This code is common to both the recording functions.  It should be
  236. ;;; branched to when the array updating is complete.
  237. ;;;
  238. ;;;
  239. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
  240. DoSignals:
  241.     MOVE.L  pubIndex(A1),D0        ; current index
  242.     CMP.L    pubHalfIndex(A1),D0    ; are we at the half-buffer point?    
  243.     BNE    PastSignalMiddle    ; 
  244.     
  245.     ; signal middle-of-buffer here 
  246.     SAVEVOLUME            ; for autodetect handling
  247.     MOVE.L    A0,A5            ; save A0 
  248.     MOVE.L    ulHalfSignal(A1),D0    ; get half-buffer signal from main
  249.     MOVE.L    stTask(A1),A1        ; get pointer to main task
  250.     JSRLIB    Signal            ; call Exec.library/Signal()
  251.     MOVE.L    A5,A0            ; retrieve A0
  252.     BRA.S    ExitHandler        ; bye bye
  253.                     ; note: D0-D1,A0-A1 trashed by system call
  254. PastSignalMiddle:
  255.     CMP.L    pubEndIndex(A1),D0    ; are we past the end of the buffer?
  256.     BLT    ExitHandler        ;
  257.  
  258.     ; reset next-byte pointer to beginning of array
  259.     MOVE.L    pubArray(A1),pubIndex(A1) ; reset counter 
  260.  
  261.     ; signal end-of-buffer here 
  262.     SAVEVOLUME            ; for autodetect handling
  263.     MOVE.L    A0,A5            ; save A0 
  264.     MOVE.L    ulFullSignal(A1),D0    ; get full-buffer signal from main
  265.     MOVE.L    stTask(A1),A1        ; get pointer to main task
  266.     JSRLIB    Signal            ; call Exec.library/Signal()
  267.     MOVE.L    A5,A0            ; retrieve A0
  268.  
  269. ExitHandler:
  270.     MOVE.W    uwClearCode+2(A1),intreq(A0) ; clear the interrupt (+2=lower WORD of ULONG)
  271.     RTS
  272.     
  273.  
  274.  
  275.  
  276.  
  277. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  278. ;;;
  279. ;;;
  280. ;;; This is an assembly language stub to help AHI's hook routines
  281. ;;;
  282. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  283. _AHIhookEntry:
  284.     move.l    a1,-(sp)        ; push message packet pointer
  285.     move.l    a2,-(sp)        ; push object pointer
  286.     move.l    a0,-(sp)        ; push hook pointer
  287.     move.l    h_SubEntry(a0),a0    ; fetch actual Hook entry point...
  288.     jsr    (a0)            ; and call it
  289.     lea    12(sp),sp        ; fix the stack
  290.     rts
  291.     
  292.         
  293.     END
  294.     
  295.     
  296.